package com.cddata.util;

import java.util.Iterator;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import com.cddata.entity.Contents;

public class DBUtil {
	 
	public static int getNewRowId( String aTableName, String aColumnName ) {
		Session session = HibernateUtil.getSessionFactory().openSession();
		String str = "SELECT MAX("+aColumnName + ") from " +aTableName ;
		Query query = session.createQuery(str);
		List list = query.list();
		Integer maxId = null;
			for( Iterator<Integer> it = list.iterator(); it.hasNext();) {
				maxId = it.next();
				if( maxId == null ) {
					maxId = 1;
				} else {
					maxId = new Integer( maxId + 1);	
				}
				
			}
		session.close();
		return maxId;
	}
	

}
